﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:SYS_LOG
	/// </summary>
	public partial class SYS_LOG : BaseDAL<GSLMS.Entity.TB_SYS_LOG>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public SYS_LOG()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_SYS_LOG model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_USERNAME", model.USERNAME),
								new OracleParameter("P_OPDATE", model.OPDATE),
								new OracleParameter("P_MODULECODE", model.MODULECODE),
								new OracleParameter("P_OPCONTENT", model.OPCONTENT),
								new OracleParameter("P_OPSIGN", model.OPSIGN),
								new OracleParameter("P_OPSQL", model.OPSQL),
								new OracleParameter("P_OPIP", model.OPIP),
								new OracleParameter("P_HOSTMAC", model.HOSTMAC)};
  
			for (int i = 0; i < 9; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
                OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_sys.proc_log_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_SYS_LOG model)
		{
			bool flag = false;

            //不再使用
            //OracleParameter[] parms = new OracleParameter[]{
            //                    new OracleParameter("P_ID", model.ID),
            //                    new OracleParameter("P_USERNAME", model.USERNAME),
            //                    new OracleParameter("P_OPDATE", model.OPDATE),
            //                    new OracleParameter("P_MODULECODE", model.MODULECODE),
            //                    new OracleParameter("P_OPCONTENT", model.OPCONTENT),
            //                    new OracleParameter("P_OPSIGN", model.OPSIGN),
            //                    new OracleParameter("P_OPSQL", model.OPSQL),
            //                    new OracleParameter("P_OPIP", model.OPIP),
            //                    new OracleParameter("P_HOSTMAC", model.HOSTMAC)};

            //for (int i = 0; i < 9; i++)
            //{
            //    parms[i].Direction = ParameterDirection.Input;
            //}

            //try
            //{
            //    OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_sys_log_update", parms);
            //    flag = true;
            //}
            //catch (Exception ex)
            //{
            //    log.ExceptionHand(ex);
            //}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
            //不再使用
            //OracleParameter[] parms =new OracleParameter[]{
            //                    new OracleParameter("P_ID", ID)};
  
            //    parms[0].Direction = ParameterDirection.Input;

            //try
            //{
            //    OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_sys_log_delete", parms);
            //    flag = true;
            //}
            //catch (Exception ex)
            //{
            //    log.ExceptionHand(ex);
            //}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_SYS_LOG DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_SYS_LOG model = new GSLMS.Entity.TB_SYS_LOG();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["USERNAME"]!=null && dr["USERNAME"].ToString()!="")
				{
					model.USERNAME=dr["USERNAME"].ToString();
				}
				if(dr["OPDATE"]!=null && dr["OPDATE"].ToString()!="")
				{
					model.OPDATE=DateTime.Parse(dr["OPDATE"].ToString());
				}
				if(dr["MODULECODE"]!=null && dr["MODULECODE"].ToString()!="")
				{
					model.MODULECODE=dr["MODULECODE"].ToString();
				}
				if(dr["OPCONTENT"]!=null && dr["OPCONTENT"].ToString()!="")
				{
					model.OPCONTENT=dr["OPCONTENT"].ToString();
				}
				if(dr["OPSIGN"]!=null && dr["OPSIGN"].ToString()!="")
				{
					model.OPSIGN=dr["OPSIGN"].ToString();
				}
				if(dr["OPSQL"]!=null && dr["OPSQL"].ToString()!="")
				{
					model.OPSQL=dr["OPSQL"].ToString();
				}
				if(dr["OPIP"]!=null && dr["OPIP"].ToString()!="")
				{
					model.OPIP=dr["OPIP"].ToString();
				}
				if(dr["HOSTMAC"]!=null && dr["HOSTMAC"].ToString()!="")
				{
					model.HOSTMAC=dr["HOSTMAC"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_SYS_LOG GetByID(long ID)
		{
			GSLMS.Entity.TB_SYS_LOG sModel = new GSLMS.Entity.TB_SYS_LOG();
			string sql = "";
			sql = "select * from TB_SYS_LOG where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_SYS_LOG> GetList(GSLMS.Entity.TB_SYS_LOG searchParam)
		{
			var list=new List<GSLMS.Entity.TB_SYS_LOG>();
			DataTable dt = null;
			string tblName = "TB_SYS_LOG";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_SYS_LOG model = new GSLMS.Entity.TB_SYS_LOG();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

